home *** CD-ROM | disk | FTP | other *** search
- #
- # MatchResult.py
- # JunkMatcher
- #
- # Created by Benjamin Han on 2/1/05.
- # Copyright (c) 2005 Benjamin Han. All rights reserved.
- #
-
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License
- # as published by the Free Software Foundation; either version 2
- # of the License, or (at your option) any later version.
-
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
-
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
- #!/usr/bin/env python
-
- from consts import *
- from utilities import *
-
-
- class MatchResultEntry (object):
- __slots__ = ('isProperty', 'idStr', 'view', 'isPositive', 'info', 'testIdx')
-
- def __init__ (self, isProperty, idStr, isPositive, view = None, info = None, testIdx = -1):
- self.isProperty = isProperty
- self.idStr = idStr
- self.isPositive = isPositive
- if view: self.view = view
- if info: self.info = info
- self.testIdx = testIdx
-
-
- class MatchResult (list):
- """Recording the verdict, each test (property/pattern) and its result
- ------------------------------------------------------------------
- verdict: True iff the message is junk; False iff it's clean; a string if it's whitelisted
- (the pattern name being matched).
- """
- # improving performance by not having __dict__
- __slots__ = 'verdict'
-
- def setVerdict (self, verdict):
- self.verdict = verdict
-
- def addProperty (self, propertyID, isPositive, info = None, testIdx = -1):
- self.append(MatchResultEntry(True, propertyID, isPositive, info = info, testIdx = testIdx))
-
- def addPattern (self, patternStr, view, isPositive, info = None, testIdx = -1):
- self.append(MatchResultEntry(False, patternStr, isPositive, view = view, info = info, testIdx = testIdx))
-